import json

data = [{
    "name": "Bob",
    "gender": "male",
    "birthday": "1992-10-18"
}, {
    "name": "Selina",
    "gender": "female",
    "birthday": "1995-10-18"
}]

with open('data.json','w',encoding='utf-8') as file:
    #dumps()方法将json对象 转化成字符串,其中每行缩进2
    file.write(json.dumps(data,indent=2))